home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / pascal / pro8 / tpalloc.doc < prev    next >
Text File  |  1988-11-04  |  4KB  |  90 lines

  1. TPALLOC - Routines for allocating blocks of memory larger than 64K
  2. ------------------------------------------------------------------
  3. Brian Foley
  4. TurboPower Software
  5. Compuserve [76317,3247]
  6. 11/88
  7. Version 1.0
  8. Released to the public domain
  9.  
  10. Overview
  11. ------------------------------------------------------------------------------
  12.  
  13. TPALLOC contains routines that allow you to allocate and deallocate blocks of
  14. memory larger than 64K using Turbo Pascal 4.0 or 5.0. Whether or not these
  15. routines will be of use to you is hard to say. On the one hand, their
  16. usefulness is severely limited by the fact that Turbo Pascal does not allow
  17. you to declare data structures larger than 64K (actually 65521 bytes). So it
  18. will be up to you to manipulate huge data structures allocated with TPALLOC.
  19. On the other hand, we know these routines *can* be useful in some cases. After
  20. all, we wrote them because we needed them for our own software. In any event,
  21. we didn't feel any overwhelming need to keep these routines to ourselves, and
  22. you are welcome to use them if you can.
  23.  
  24. See DEMO.PAS for a demonstration of how to use TPALLOC.
  25.  
  26. Using TPALLOC
  27. ------------------------------------------------------------------------------
  28.  
  29. TPALLOC interfaces the following types and procedures:
  30.  
  31. type
  32.   SegOfs =
  33.     record
  34.       Ofst, Segm : Word;
  35.     end;
  36.  
  37.   This record structure is used to separate a 32-bit pointer into its
  38.   component parts.
  39.  
  40. procedure HugeGetMem(var Pt; Bytes : LongInt);
  41.  
  42.   This routine allocates a block of memory of size Bytes and stores a pointer
  43.   to it in Pt (a pointer variable of some sort). Pt will be set to nil if
  44.   Bytes > MaxAvail. HugeGetMem is essentially identical to GetMem except that
  45.   it can allocate blocks of memory larger than 64K. (It can also allocate
  46.   blocks less than 64K, of course.)
  47.  
  48. procedure HugeFreeMem(var Pt; Bytes : LongInt);
  49.  
  50.   This routine deallocates a block of memory of size Bytes pointed to by Pt (a
  51.   pointer variable of some sort). Pt is set to nil on exit. HugeFreeMem does
  52.   nothing if Pt is nil to begin with. HugeFreeMem is essentially identical to
  53.   FreeMem except that it can deallocate blocks of memory larger than 64K. (It
  54.   can also deallocate blocks less than 64K, of course.)
  55.  
  56. The following routines are used internally, but they're interfaced in case you
  57. need or want to use them. They are especially useful when performing pointer
  58. arithmetic, something you'll probably need to do if you're working with data
  59. structures larger than 64K.
  60.  
  61. function Linear(P : Pointer) : LongInt;
  62.  
  63.   Converts a pointer to a linear address to allow differences in addresses to
  64.   be calculated. The pointer must be in the range $0:$0 to $FFFF:$000F.
  65.  
  66. function LinearToPointer(L : LongInt) : Pointer;
  67.  
  68.   Returns linear address L as a normalized pointer.
  69.  
  70. function PtrDiff(P1, P2 : Pointer) : LongInt;
  71.  
  72.   Returns the number of bytes between P1^ and P2^. The order of P1 and P2 is
  73.   not important.
  74.  
  75. function Normalized(P : Pointer) : Pointer;
  76.  
  77.   Returns P as a normalized pointer. Not used in TPALLOC, but useful when
  78.   doing pointer arithmetic.
  79.  
  80. Limitations
  81. ------------------------------------------------------------------------------
  82.  
  83. It is perfectly safe to use HugeGetMem and HugeFreeMem in combination with
  84. Turbo Pascal's standard memory management routines. Both routines keep the
  85. heap manager's free list in order, and they rely on no status variables other
  86. than those used by Turbo Pascal itself (HeapPtr, FreePtr, and FreeMin). The
  87. only limitation of these routines that we are currently aware of is that
  88. HugeFreeMem does not check to make sure that the pointer variable passed to it
  89. is valid. (It does check for a nil pointer, however, as noted above.)
  90.